package com.collectionAndMap.map;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/***
 * @ClassName: HashMapDemo
 * @Description: 数组 链表 红黑树
 * @Auther: 送一一块二向箔
 * @Date: 11:13 2022/2/18
 * @version : V1.0
 */
public class HashMapDemo {
    public static void main(String[] args) {
        HashMap<Girl, String> hashMap = new HashMap<>();
        Girl a = new Girl("小红", 1);
        Girl b = new Girl("小蓝", 2);
        Girl c = new Girl("小绿", 3);
        Girl d = new Girl("小紫", 4);

        hashMap.put(a,"aaa");
        hashMap.put(b,"bbb");
        hashMap.put(c,"ccc");
        hashMap.put(null,"fff");
        System.out.println(hashMap.put(d, "ddd"));
        //没重写前是可以加进去的，因为对象地址不一样，所以hashCode不一样
        String put = hashMap.put(new Girl("小紫", 4), "eee");

        //返回重复的key对应的value
        System.out.println(put);
        System.out.println(hashMap.toString());

        Set<Map.Entry<Girl, String>> entries = hashMap.entrySet();
        System.out.println("===="+entries);
        for (Map.Entry<Girl, String> girlStringEntry : hashMap.entrySet()) {
            System.out.println(girlStringEntry.getValue());
        }
    }
}
